/**
 * copyright (c) by handpay 2013
 */
package com.handpay.framework.ui;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;

import com.handpay.zztong.hp.R;

/**
 * POS机样式的键盘
 * 
 * @author：Klaus Liu E-mail: lpluck08@gmail.com
 * @date：2013-3-21 下午02:37:14
 */
public class HPPOSKeyboard extends HPKeyBoard implements View.OnClickListener {
	private POSKeyboardOnClickButtonLinster	clickButtonLinster;

	private static final int[]				idButtonNumbers	= new int[] {
			R.id.hpKbNum0, R.id.hpKbNum1, R.id.hpKbNum2, R.id.hpKbNum3,
			R.id.hpKbNum4, R.id.hpKbNum5, R.id.hpKbNum6, R.id.hpKbNum7,
			R.id.hpKbNum8, R.id.hpKbNum9, R.id.hpKbDot, R.id.hpKbDouble0 };

	public HPPOSKeyboard(Context context, AttributeSet attrs) {
		super(context, attrs);

		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		inflater = LayoutInflater.from(context);
		inflater.inflate(R.layout.hp_vpos_keyboard, this);

		for (int i = 0; i < idButtonNumbers.length; i++) {
			findViewById(idButtonNumbers[i])
					.setOnClickListener(this);
		}
		findViewById(R.id.hpKbCancle).setOnClickListener(this);
		findViewById(R.id.hpKbDelete).setOnClickListener(this);
		findViewById(R.id.hpKbOk).setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
        int i = v.getId();
        if (i == R.id.hpKbCancle) {
            this.clickButtonLinster.onClickCancel();
        } else if (i == R.id.hpKbDelete) {
            this.clickButtonLinster.onClickDelete();
        } else if (i == R.id.hpKbOk) {
            this.clickButtonLinster.onClickOK();
        } else {
            this.clickButtonLinster.onClickNumButton(((Button) v).getText()
                    .toString());
        }
	}

	public void setClickButtonLinster(
			POSKeyboardOnClickButtonLinster clickButtonLinster) {
		this.clickButtonLinster = clickButtonLinster;
	}

	public interface POSKeyboardOnClickButtonLinster extends
			OnClickButtonLinster {
		/**
		 * 点击Cancel回调
		 * 
		 * @param text
		 */
		void onClickCancel();
	}
}
